package com.ge.boot11actuator.HealthIndicator;

import com.ge.boot11actuator.component.MyAppComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.stereotype.Component;

/**
 * 测试定制健康监测端点<br>
 * 继承AbstractHealthIndicator，重新doHealthCheck方法<br>
 * 由业务组件提供状态判断的方法，此处只做调用
 */
@Component
public class MyHealthIndicator extends AbstractHealthIndicator {

    @Autowired
    MyAppComponent appComponent;

    @Override
    protected void doHealthCheck(Health.Builder builder) {

        if (appComponent.doCheck() == 1){
            // 构建存活状态
            builder.up().build();
        } else {
            builder.down().build();
        }
    }
}
